package com.wxtf.platform.supers;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/*******************************************************************************
 * @author 黄威
 ******************************************************************************/
public abstract class LogicBase{

	static Log logger = LogFactory.getLog(LogicBase.class);

	private final String VERSION = "1.0";

	public String getVersion() {
		return VERSION;
	}

	private int start = 0;
	private int limit = 50;
	private int page = 0;
	private int pagesize = 50;
	protected String sql = null;
	private String logicData = null;
	private String extendData = null;
	private String methodName = null;
	private String className = null;
	
	// 20120725
	public HttpServletRequest request = null;

	public boolean parseJSON(String jsonArray_) {
		boolean bRe = false;
		try {
			JSONObject jsonObject = null;
			JSONArray jsonArray = JSONArray.fromObject(jsonArray_);
			for(int i1 = 0; i1 < jsonArray.size(); i1++) {
				jsonObject = JSONObject.fromObject(jsonArray.getString(i1));
				logger.info(jsonObject.getString("id"));
			}
			bRe = true;

		} catch(Exception ex) {
			ex.printStackTrace();
		}
		return bRe;
	}

	public abstract Object run();

	public abstract Object select(Object jsonArray) throws Exception;

	public abstract Object insert(Object jsonArray) throws Exception;

	public abstract Object update(Object jsonArray) throws Exception;

	public abstract Object delete(Object jsonArray) throws Exception;

	public abstract Object updateBatch(Object jsonArray) throws Exception;

	public abstract Object recordCount(Object jsonArray) throws Exception;

	public abstract Object setRequest(HttpServletRequest request) throws Exception;

	public void clear() {
		page = 0;
		pagesize = 50;
		sql = null;
		logicData = null;
		extendData = null;
		methodName = null;
		className = null;
	}
	
	public String getLogicData() {
		return logicData;
	}

	public void setLogicData(String logicData) {
		this.logicData = logicData;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getExtendData() {
		return extendData;
	}

	public void setExtendData(String extendData) {
		this.extendData = extendData;
	}

	public HttpServletRequest getRequest() {
		return this.request;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		if(pagesize == 10) {
			pagesize = 20;
		}
		this.pagesize = pagesize;
	}

}
